home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 January / PSL Monthly Shareware CD-ROM (Public Software Library) (January 1994).iso / games / dos / misc / drain.com / DRAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-27  |  8.0 KB  |  254 lines

  1. /* DRAIN, Version 3: spin dry modification.
  2.  
  3.      My thanks to James R. Maynard III, a good friend, fellow
  4.      firefighter and ham for taking on the suggestions (and
  5.      accusations that he wrote 'DRAIN1') and improved it while
  6.      also providing us wanna-be programmers with the source code
  7.      to his project. With that and a little help from George
  8.      Henderson (showing me how to use TurboC) I 'hacked' a little
  9.      and came up with the fixes to non-incremental spin-dry.
  10.      Some say they like this girgle better (ver2), maybe so. How
  11.      the original author did the good flush the first time we
  12.      have yet to figure out.
  13.      Chock this up to good old non-virus software. This is a CLEAN
  14.      prank...and damn those who don't continue to include the Source
  15.      code, and especially those who take this reputable clean file
  16.      and screw up someone's system with it.....if you do -
  17.      may all your floppies flop and your hard drive go limp, ah,er
  18.      soft forever !
  19.      My wishes for keeping the original file/comments intact, and any
  20.      changes only additive, for the better, accompany those of
  21.      Mr. Maynard...
  22.      Grapevine P.C. Associates
  23.      Jim Aspinwall, The Source, AAJ696
  24. */
  25.  
  26. /* Drain, version 2: better prompt handling.
  27.  
  28.      I don't claim credit for this idea, and the original perpretrator
  29.      is lost in the mists of time...but I liked the idea. The original
  30.      program only had one problem, though: It ignored the user's
  31.      PROMPT setting. That made it somewhat transparent, since not many
  32.      people any more run from drive A, and darned few of them use a
  33.      yellow prompt! I got Turbo C, and decided this would be a good
  34.      learning project.
  35.  
  36.      This program is (C) Copyright 1987, James R. Maynard III
  37.                              6027 Leafwood Circle
  38.                              League City, Texas 77573
  39.      This program may be copied and distributed freely, with only
  40.      one restriction: These comments must not be modified. (After
  41.      all, we all would like to be known for SOMETHING!) If you come
  42.      up with improvements, please let me know so I can enjoy them
  43.      too. Send me mail at the above address, or to my GEnie mailbox
  44.      (JAYMAYNARD), my Compu$erve mailbox (71036,1603), or my FidoNode
  45.      (Graf Spee, 106/64). I hope to have a usenet address soon...
  46. */
  47.  
  48. #include <stdio.h>
  49. #include <dir.h>
  50. #include <math.h>
  51. #include <bios.h>
  52. #include <dos.h>
  53.  
  54. #define MAXPROMPT 80
  55.  
  56. main()
  57. {
  58.      char promptstr[MAXPROMPT];
  59.      void getprompt(), clrscr(), draindrive();
  60.  
  61.      getprompt(promptstr);    /* get the user's prompt, or default */
  62.      clrscr();      /* clear the screen? */
  63.      printf("%s",promptstr);  /* write the bogus prompt */
  64.      getch();       /* wait for a key */
  65.      draindrive();       /* do the draining */
  66. }
  67.  
  68. void getprompt(str)
  69. char *str;
  70. {
  71.      char *envprompt, *getenv(), promptchar;
  72.      int putpath(), putdate(), puttime(), putver();
  73.  
  74.      if ((envprompt = getenv("PROMPT")) != NULL) {
  75.           for ( ; (promptchar = *envprompt) != 0; envprompt++, str++) {
  76.                if (promptchar == '$') {
  77.                     promptchar = *++envprompt;
  78.                     switch (promptchar) {
  79.                          case '$': *str = '$';
  80.                                 break;
  81.                          case '_': *str = '\n';
  82.                                 break;
  83.                          case 'T':
  84.                          case 't': str += puttime(str);
  85.                                 break;
  86.                          case 'D':
  87.                          case 'd': str += putdate(str);
  88.                                 break;
  89.                          case 'N':
  90.                          case 'n': *str = getdisk()+'A';
  91.                                 break;
  92.                          case 'G':
  93.                          case 'g': *str = '>';
  94.                                 break;
  95.                          case 'L':
  96.                          case 'l': *str = '<';
  97.                                 break;
  98.                          case 'B':
  99.                          case 'b': *str = '|';
  100.                                 break;
  101.                          case 'H':
  102.                          case 'h': *str = '\b';
  103.                                 break;
  104.                          case 'E':
  105.                          case 'e': *str = '\x1B';
  106.                                 break;
  107.                          case 'Q':
  108.                          case 'q': *str = '=';
  109.                                 break;
  110.                          case 'P':
  111.                          case 'p': str += putpath(str);
  112.                                 break;
  113.                          case 'V':
  114.                          case 'v': str += putver(str);
  115.                                 break;
  116.                     }
  117.                }
  118.                else *str = promptchar;
  119.           }
  120.           *str = '\0';
  121.      }
  122.      else {
  123.           *str++ = getdisk() + 'A';
  124.           strcpy(str,">");
  125.      }
  126. }
  127.  
  128. int putpath(char *str)
  129. {
  130.      char *curdir;
  131.      int pathlen;
  132.  
  133.      curdir = getcwd(NULL,80);
  134.      strcpy(str,curdir);
  135.      pathlen = strlen(curdir) - 1;
  136.      free(curdir);
  137.      return(pathlen);
  138. }
  139.  
  140. int putver(char *str)
  141. {
  142.      int i;
  143.      FILE *verfile;
  144.      char version[MAXPROMPT];
  145.  
  146.      system("ver >$$drain$.$$$");
  147.      verfile = fopen("$$drain$.$$$","r");
  148.      fgets(version,MAXPROMPT,verfile);
  149.      fgets(version,MAXPROMPT,verfile);
  150.      strcpy(str,version);
  151.      fclose(verfile);
  152.      unlink("$$drain$.$$$");
  153.      return(strlen(version) - 2);
  154. }
  155.  
  156. int puttime(char *str)
  157. {
  158.      int i;
  159.      struct time now;
  160.  
  161.      gettime(&now);
  162.      sprintf(str,"%2d:%02d:%02d.%02d",now.ti_hour,now.ti_min,now.ti_sec,
  163.           now.ti_hund);
  164.      return(10);
  165. }
  166.  
  167. int putdate(char *str)
  168. {
  169.      int i;
  170.      long secs_now;
  171.      struct date today;
  172.  
  173.      getdate(&today);
  174.      time(&secs_now);
  175.      strncpy(str,ctime(&secs_now),4);
  176.      str += 4;
  177.      sprintf(str,"%2d-%02d-%04d",today.da_mon,today.da_day,today.da_year);
  178.      return(13);
  179. }
  180.  
  181. void clrscr()
  182. {
  183.      union REGS regs;
  184.  
  185.      regs.h.ah = 15; /* get video mode */
  186.      int86(0x10,®s,®s);
  187.      regs.h.ah = 0;  /* set video mode, left in AL by previous call */
  188.      int86(0x10,®s,®s);
  189. }
  190.  
  191. void draindrive()
  192. {
  193.      void tone(int hertz, int ticks);
  194.      void slidetone(int start, int finish, int inc);
  195.      int freq, i;
  196.      char curdrive;
  197.  
  198.      curdrive = getdisk() + 'A';
  199.      puts(" *** SYSTEM ERROR ***");
  200.      printf("Water has been detected in drive %c. Drive cleanup",curdrive);
  201.      puts(" in progress.\nThis will take a few moments.");
  202.      puts("\nDrain phase beginning...");
  203.      for (i = 7000; i > 50; i *= 0.96) {
  204.           freq = rand() / 32768.0 * i + 50.0;
  205.           tone(freq,1);
  206.      }
  207.      puts("Drain phase complete.\n");
  208.      sleep(2);
  209.      puts("Spin dry phase beginning...");
  210.      for (i = 100; i <= 1000; i += 100) {
  211.           slidetone(i - 100,i,1);
  212.           tone(i,0);
  213.      }
  214.      tone(i-100,16);
  215.      slidetone(900,0,-5);
  216.      puts("Spin dry phase complete.\n\nDrive cleanup complete.");
  217.      puts("You may continue your work.");
  218. }
  219.  
  220. void tone(int hertz, int ticks)
  221. {
  222.      long begintime;
  223.      char bits;
  224.      int count;
  225.  
  226.      begintime = biostime(0,0L);
  227.      bits = inportb(0x61);
  228.      count = 1193280 / hertz;
  229.      outportb(0x43,0xB6);
  230.      outportb(0x42,count & 0xFF);
  231.      outportb(0x42,count >> 8);
  232.      outportb(0x61,bits | 0x03);
  233.      while (biostime(0,0L) < begintime + ticks)
  234.           ;    /* do nothing */
  235.      outportb(0x61,bits);
  236. }
  237.  
  238. void slidetone(int start, int finish, int inc)
  239. {
  240.      char bits;
  241.      int count, hertz, j;
  242.  
  243.      bits = inportb(0x61);
  244.      outportb(0x61,bits | 0x03);
  245.      for (hertz = start; hertz != finish; hertz += inc) {
  246.           count = 1193280 / hertz;
  247.      /*   outportb(0x43,0xB6); */
  248.           outportb(0x42,count & 0xFF);
  249.           outportb(0x42,count >> 8);
  250.           for (j = 0; j < 300; j++) ;
  251.      }
  252.      outportb(0x61,bits);
  253. }
  254.